package GUI;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.table.AbstractTableModel;

import Control.Ctr;
import Model.Booking;
import Model.Coach;
import Model.Invoice;
import Model.Subscription;
import Model.Client;

public class BookingTable extends AbstractTableModel {

private static final String[] columnNames = { "bID", "Date" , "Client Name", "Coach", "Start hour", "End hour", "Invoice nr.", "Total Paid" };
private Ctr ctr;
private Subscription sub;
private Coach ch;
private Invoice i;
private Client c;
private ArrayList<Booking> booking;
public BookingTable(){
	booking = new ArrayList<Booking>();
	ctr = new Control.Ctr();
	sub = new Model.Subscription();
	for(Booking e : ctr.findAllBooking() )
	{booking.add(e);
	}
}
public BookingTable(Booking c)
{	ctr = new Control.Ctr();
	booking = new ArrayList<Booking>();
	booking.add(c);}

public BookingTable(String s)
{ 
booking = new ArrayList<Booking>();
ctr = new Control.Ctr();
sub = new Model.Subscription();
for(Booking e : ctr.findAllBooking() )
{	if(e.getDate_time().equals(s))
	booking.add(e);
}
	}

@Override
public int getColumnCount() {
    // 
    return columnNames.length;
}

@Override
public int getRowCount() {
    return booking.size();
}

@Override
public String getColumnName(int column) {
    return columnNames[column];
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
     {
    	switch (columnIndex){
    case 0:
        return booking.get(rowIndex).getbID();
    case 1:
    	return booking.get(rowIndex).getDate_time();
    case 2:
    	int a = booking.get(rowIndex).getcID();
    	c = ctr.findBycID(a);
    	String name = c.getFname() ;//+ " "+ c.getLname();
        return name;
    case 3:
    	ch = ctr.findBychID(booking.get(rowIndex).getchID());
    	return ch.getName();
    case 4:
        return booking.get(rowIndex).getsStart();
    case 5:
    	return booking.get(rowIndex).getsEnd();
    case 6:
    	i =ctr.findByiID(booking.get(rowIndex).getiID());
    	
    	return i.getiID();
    case 7:
    	//c =ctr.findBycID(booking.get(rowIndex).getcID());
    	//sub = ctr.findBymID(c.getmID());
    	i = ctr.findByiID(booking.get(rowIndex).getiID());
    	
    	/*int s = c.getSession();
    	int p = sub.getPrice();
    	int l = sub.getDiscount();
    	int x = s * p - s*l;*/
    	//ch = ctr.findBychID(booking.get(rowIndex).getchID());
    	//int price = ctr.
    	return i.getPrice(); 
    			}
    }
    
    return null;
}   
}
